<!DOCTYPE html>
<?php

require_once ('conn.php');
require_once ('top.php');
if($_SESSION['role']==2){
     Header("Location:supply.php"); 
    }elseif($_SESSION['role']==3){
     Header("Location:dotlistMaster.php"); 
   }
?>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>优易购</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" type="text/css" href="css/style.css">
        <link rel="stylesheet" href="css/fakeLoader.css">
    <script src="js/jquery-1.11.0.min.js"></script>
</head>
<body>
    <div class="top">
       <a href="newwd.php"><div class="tleft">+ 新增网点</div></a>
        <span>市场人员 - 首页</span>
        <div class="tright"><span class="outlogin">退出登陆</span></div>
    </div>
    
    
    <?php
    $result=mysql_query("select * from ci_contact where disable=0 and isDelete=0 and staffid=".$_SESSION['userid']); 
    $i=0;
    $Total;//总库存
    $Surplus;//当前库存
    $num;//交易额
   
    while($row=mysql_fetch_array($result)) 
    {
         $but=0;//是否显示补货按钮
         $Total = mysql_fetch_row(mysql_query("select SUM(qty) from ci_invoice_info where buId =$row[id] and transType = 150601 and isDelete = 0"));
         if($Total[0]==""||$Total[0]==0){
             $Total =0;
         }else{
             $Total =$Total[0]*-1;
         }
        
        $button = mysql_fetch_row(mysql_query("select SUM(num) from ci_wx_order_goods where customerNumber ='".$row['number']."'  and status=0 and payStatus = 1"));
        $Surplus = mysql_fetch_row(mysql_query("select SUM(num) from ci_wx_order_goods where customerNumber ='".$row['number']."' and payStatus = 1"));
         if($Surplus[0]==""||$Surplus[0]==0){
             $Surplus =$Total;
         }else{
             $but=$button[0];
             $Surplus =$Total-$Surplus[0];
         }
        $result2=mysql_query("select num,goodsPrice from ci_wx_order_goods where customerNumber ='".$row['number']."' and payStatus = 1");
        $num=0;
        while($n=mysql_fetch_array($result2)) 
        {
            $num=$num+$n[0]*$n[1];
        }
     $i++;
   ?>
   
   
    
    <div class="list2" onclick="window.open('market_info.php?contactNumber=<?=$row['number']?>','_self')">
        <div class="list90">
            <div class="dingwei">
                <img src="img/dingwei.png" alt="">
                <span><?=$row['name']?></span>
            </div>
            <div class="shuju">
                <div class="sj33">
                    <p class="sj33p1 Total<?=$row['id']?>"><?=$Total?></p>
                    <p class="sj33p2">总库存</p>
                </div>
                <div class="sj33">
                    <p class="sj33p1 Surplus<?=$row['id']?>"><?=$Surplus?></p>
                    <p class="sj33p2">当前库存</p>
                </div>
                <div class="sj33">
                    <p class="sj33p3 num<?=$row['id']?>">+<?=$num?></p>
                    <p class="sj33p2">交易额</p>
                </div>
            </div>
            <div class="i">
                <img src="img/i.png" alt="">
                <span>成本：--</span>
                <?php if($but>0){?>
                
                   <div class="i_right buhuo<?=$row['id']?>" id="buhuo"  onclick="buhuo(<?=$row['id']?>);(function(e){
    var e = window.event || e;
    if (e.stopPropagation) e.stopPropagation();
    else e.cancelBubble = true;
})(event)">
                   补货
                   </div>

             <?php  }else{?>
       
               <div class="i_righthui">补货</div>   
                <?php }?>
                
            </div>
            
        </div>
    </div>

    <?php
    }
    ?>
    
    <div style=" width:100%;height:100px; float:left;"></div>
    <div class="foot">
        <a href="index.php">
        <div>
        <img src="img/f11.png" alt="">
        <p>首页数据</p>
        </div>
        </a>
        <div class="footon">
        <img src="img/f2.png" alt="">
        <p>全部网点</p>
        </div>
        <a href="#">
        <div>
        <img src="img/f33.png" alt="">
        <p>补货记录</p>
        </div>
        </a>
    </div>
    <div class="fakeloader"></div>
</body>
 <script src="js/fakeLoader.min.js"></script>
<script>
function buhuo(buId){
     if(!confirm("是否确认补货？")){ 
 return false; 
}
$(".fakeloader").fakeLoader({
	            timeToHide:60000,
	            bgColor:"rgba(0, 0, 0, 0.5)",
	            spinner:"spinner2"
});
 $.post("ajaxbuhuo.php",{buId:buId},function(data) {
	if(data=="y"){
         history.go(0);
  }								
 });
}
</script>
<script src="js/outlogin.js"></script>

</html>